<!--
  Copyright © 2016 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="no-content-message text-center" ng-if="Lineage.nodes.length === 0">
  <p>No lineage data for the selected time period</p>
</div>

<div class="lineage-diagram-container" id="lineage-diagram"
     style="height: {{Lineage.graphInfo.height}}px; width: {{Lineage.graphInfo.width}}px; transform: scale({{ Lineage.scaleInfo.scale }}); left: {{ Lineage.scaleInfo.padX }}; top: {{ Lineage.scaleInfo.padY }};">
  <div class="nodes {{ Lineage.uniqueNodes[node.uniqueNodeId].nodeType }}"
       id="{{ node.dataId }}"
       ng-repeat="node in Lineage.nodes"
       ng-style="node._uiLocation"
       ng-click="Lineage.nodeClick($event, node)">

    <!-- Navigation -->
    <div class="navigation-control left"
         ng-if="node.isLeftEdge">
      <span class="fa fa-caret-left" ng-click="Lineage.navigationClick($event, node)"></span>
    </div>
    <div class="navigation-control right"
         ng-if="node.isRightEdge">
      <span class="fa fa-caret-right" ng-click="Lineage.navigationClick($event, node)"></span>
    </div>

    <a class="entity-link" ui-sref="{{ Lineage.constructNodeLink(node) }}"
       ng-if="Lineage.uniqueNodes[node.uniqueNodeId].nodeType === 'data'">
      <h4 class="entity-name">{{ Lineage.uniqueNodes[node.uniqueNodeId].label }}</h4>
      <div class="entity-type">
        <span class="{{ Lineage.uniqueNodes[node.uniqueNodeId].icon }}"></span>
        <span>{{ Lineage.uniqueNodes[node.uniqueNodeId].displayType }}</span>
      </div>
    </a>

    <a href="" class="entity-link"
       ng-if="Lineage.uniqueNodes[node.uniqueNodeId].nodeType === 'program'">
      <h4 class="entity-name">{{ Lineage.uniqueNodes[node.uniqueNodeId].applicationId }}</h4>
      <div class="entity-type">
        <span class="{{ Lineage.uniqueNodes[node.uniqueNodeId].icon}}"></span>
        <span>{{ Lineage.uniqueNodes[node.uniqueNodeId].label }}</span>
      </div>
    </a>


    <!-- PROGRAM POPOVER -->
    <div class="tracker-program-popover" ng-if="node.showPopover" ng-click="Lineage.preventPropagation($event)">
      <div class="tracker-popover-content">
        <div class="top-bar">
          <div class="row">

            <div class="col-xs-8">
              <div class="entity-detail">
                <h4>
                  <a ui-sref="{{ Lineage.constructProgramLink(node) }}">
                    {{ Lineage.uniqueNodes[node.uniqueNodeId].label }}
                  </a>
                </h4>
                <div class="entity-type">
                  <span class="{{ Lineage.uniqueNodes[node.uniqueNodeId].icon }}"></span>
                  <span>{{ Lineage.uniqueNodes[node.uniqueNodeId].displayType }}</span>
                </div>
              </div>
            </div>

            <div class="col-xs-4">
              <div class="runs-controller text-center">
                <h5>Runs</h5>
                <div class="runs-navigation">
                  <span class="fa fa-caret-left" ng-click="Lineage.prevRun($event, node)"></span>
                  <span>{{ node.popover.activeRunIndex + 1 }}/{{ Lineage.uniqueNodes[node.uniqueNodeId].runs.length }}</span>
                  <span class="fa fa-caret-right" ng-click="Lineage.nextRun($event, node)"></span>
                </div>
              </div>
            </div>

            <div class="close-button">
              <span class="fa fa-close" ng-click="Lineage.closePopover($event, node)"></span>
            </div>
          </div>
        </div>

        <div class="info-container">
          <div class="row">
            <div class="col-xs-12">
              <div class="inside-column">
                <h5>Run ID</h5>
                <div>
                  <span>{{ node.popover.activeRunId }}</span>
                </div>
              </div>
            </div>
          </div>

          <div class="row">
            <div class="run-detail inside-column">
              <div class="col-xs-5">
                <h5>
                  Started
                </h5>
                <div>
                  <span> {{ node.popover.runInfo.start | amDateFormat: 'ddd,  MM/DD/YY h:mm:ss a' }} </span>
                </div>
              </div>

              <div class="col-xs-3">
                <h5>
                  Duration
                </h5>
                <div>
                  <span>{{ node.popover.runInfo.duration | amDurationFormat }}</span>
                </div>
              </div>

              <div class="col-xs-4">
                <h5>
                  Status
                </h5>
                <div>
                  <span class="fa fa-circle"
                        ng-class="{'text-success': node.popover.runInfo.status === 'COMPLETED' || node.popover.runInfo.status === 'RUNNING', 'text-danger': node.popover.runInfo.status !== 'COMPLETED' && node.popover.runInfo.status !== 'RUNNING'}"
                  ></span>
                  <span>{{ node.popover.runInfo.status }}</span>
                </div>
              </div>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>
</div>
